package game.source.gui;

import java.awt.image.BufferedImage;

public class RespawnFilter{
	private static int counter_region = 0;
	private static int counter_value = 0;
	private static int[][] previus;

	private static int newPixel(int RGBA){
		int alpha = RGBA & 0XFF000000;
		if(alpha != 0){
			return (RGBA & 0x00FFFFFF)+0X80000000;
		}else{
			return RGBA;
		}
	}
	public synchronized static void filter(BufferedImage src,BufferedImage dest){
		if(counter_region % 2 == 0){
			previus = new int[src.getWidth()][src.getHeight()];
			for(int i = 0; i < src.getWidth(); i++){
				for(int j = 0; j < src.getHeight(); j++){
					previus[i][j] = src.getRGB(i, j);
					dest.setRGB(i, j,newPixel(src.getRGB(i,j)));
				}
			}
		}
		counter_value++;
		if(counter_value % 5 == 0){
			counter_value = 0;
			counter_region++;
		}
	}
	public synchronized static void returnsPrevius(BufferedImage dest){
		if(counter_value == 0){
			if((counter_region-1) % 2 ==0){
				for(int i = 0; i < dest.getWidth(); i++){
					for(int j = 0; j < dest.getHeight(); j++){
						dest.setRGB(i, j,previus[i][j]);
					}
				}
			}
		}else{
			if(counter_region % 2 == 0){
				for(int i = 0; i < dest.getWidth(); i++){
					for(int j = 0; j < dest.getHeight(); j++){
						dest.setRGB(i, j,previus[i][j]);
					}
				}
			}
		}
	}
}
